package com.bicon.botu.mall.order.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.bicon.botu.mall.order.service.IOrderItemService;
import com.bicon.botu.core.base.common.Constants;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.mall.order.dto.OrderDto;
import com.bicon.botu.mall.order.entity.GoodsOrder;
import com.bicon.botu.mall.order.service.IGoodsOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 后台订单接口
 *
 * @auther 裴志鹏
 * @date 2017/7/20 10:44
 */
@Slf4j
@RestController
@RequestMapping("/V1.0.0/goodsOrder")
public class GoodsOrderController extends BaseController {

    @Autowired
    private IGoodsOrderService iGoodsOrderService;

    @Autowired
    private IOrderItemService iOrderItemService;

    /**
     * 修改订单接口
     *
     * @param orderId      订单id
     * @param actualAmount 实际支付金额
     * @param name         收货人
     * @param address      收货地址
     * @param telephone    联系电话
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public BaseResult update(@RequestParam String orderId, String actualAmount, String name, String address, String telephone) {
        return iGoodsOrderService.update(orderId, actualAmount, name, address, telephone);
    }

    /**
     * 无效
     *
     * @param goodsOrderId 订单id
     * @return
     */
    @RequestMapping(value = "/updateByOrderId", method = RequestMethod.POST)
    public BaseResult updateByOrderId(@RequestParam String goodsOrderId) {
        return iGoodsOrderService.updateByOrderId(goodsOrderId);
    }

    /**
     * 移除
     *
     * @param goodsOrderId 订单id
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public BaseResult delete(@RequestParam String goodsOrderId) {
        GoodsOrder goodsOrder = new GoodsOrder();
        goodsOrder.setId(goodsOrderId);
        boolean b = goodsOrder.deleteById();
        if (b) {
            return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200);
        } else {
            return new BaseResult(Constants.RESPONSE_CODE_500, Constants.RESPONSE_MESSAGE_500);
        }
    }


    /**
     * 分页查询订单列表
     *
     * @param pageNo   页码
     * @param pageSize 每页显示数量
     * @return
     */
    @RequestMapping(value = "/findOrderList", method = RequestMethod.POST)
    public BaseResult findOrderList(@RequestParam int pageNo, @RequestParam int pageSize) {
        Page<OrderDto> page = iGoodsOrderService.findOrderList(pageNo, pageSize);
        return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, page);
    }

    /**
     * 商品详情
     *
     * @param orderId 订单id
     * @return
     */
    @RequestMapping(value = "/findGoodsByOrderId", method = RequestMethod.POST)
    public BaseResult findGoodsByOrderId(@RequestParam String orderId) {
        return iOrderItemService.findGoodsByOrderId(orderId);
    }

    /**
     * 按类型查询订单列表
     *
     * @param pageNo   页码
     * @param pageSize 每页显示数量
     * @param type     发货、退货、退换货类型
     * @return
     */
    @RequestMapping(value = "/findOrderByPayment", method = RequestMethod.POST)
    public BaseResult findOrderByPayment(@RequestParam int pageNo, @RequestParam int pageSize, @RequestParam String type) {
        Page<OrderDto> page = iGoodsOrderService.findOrderByPayment(pageNo, pageSize, type);
        return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, page);
    }

}